package com.itheima.skyserver.controller;

import com.itheima.skyserver.pojo.domain.Employee;
import com.itheima.skyserver.pojo.vo.EmpLoginVo;
import com.itheima.skyserver.result.Result;
import com.itheima.skyserver.service.EmployeeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping("/admin/employee")
@Slf4j
@RestController
public class EmployeeController {


    @Autowired
    private EmployeeService employeeService;



    @PostMapping("/login")
    public Result login(@RequestBody Employee employee){
        //1.接收请求参数：JSON格式
        log.info("员工登录：{}",employee);

        //2.调用service层，完成登录操作
        Employee loginEmp = employeeService.checkLogin(employee);


        //3.封装返回结果
        EmpLoginVo empLoginVo = new EmpLoginVo();
        empLoginVo.setId(loginEmp.getId());
        empLoginVo.setName(loginEmp.getName());
        empLoginVo.setUsername(loginEmp.getUsername());

        return  Result.success(empLoginVo);
    }


}
